/**
 * AgaEngine (c)2011.
 * FileName:GameTool.java
 */
package aga.engine.tools;


/**
 * 
 * @author zhe.yangz
 */
public class GameTool {
	//===========================================================
	//Constants
	//===========================================================

	//===========================================================
	//Fields
	//===========================================================

	//===========================================================
	//Constructors
	//===========================================================

	//===========================================================
	//Getter & Setter
	//===========================================================

	//===========================================================
	//Methods for/from SuperClass/Interfaces
	//===========================================================

	//===========================================================
	//Methods
	//===========================================================

	public static int checkAdjustAngle(int srcAngle, int distAngle, int adjustAngle) {
		int retAngle = adjustAngle;
		
/*		if (srcAngle == distAngle) {
			return 0;
		} else if (srcAngle > (distAngle+adjustAngle)) {
			retAngle = -adjustAngle;
		} else if (srcAngle < (distAngle-adjustAngle)){
			retAngle = adjustAngle;
		} else {
			retAngle = -srcAngle + distAngle;
		}*/
		
		int diffAngle = distAngle - srcAngle;
		
		if (diffAngle == 0) {
			return 0;
		} else if (Math.abs(diffAngle)<=adjustAngle) {
			retAngle = diffAngle;
		} else if (diffAngle > adjustAngle && diffAngle <= 180) {
			retAngle = adjustAngle;
		} else if (diffAngle > 180){
			retAngle = -adjustAngle;
		} else if (diffAngle < -adjustAngle && diffAngle >= -180) {
			retAngle = -adjustAngle;
		} else if (diffAngle < -180) {
			retAngle = adjustAngle;
		}
		if (srcAngle + retAngle < 0) {
			retAngle += 360;
		} else if (srcAngle + retAngle >= 360) {
			retAngle -= 360;
		}
		
		return retAngle;
	}
	//===========================================================
	//Inner and Anonymous Classes
	//===========================================================

	/**
	 * @param speed
	 * @param angle
	 * @return
	 */
	public static float checkAdjustX(float speed, float angle) {
		float xDiff = 0;
		
		xDiff = (float)(speed * Math.cos(angle/180.0f*Math.PI));
		
		return xDiff;
	}

	/**
	 * @param speed
	 * @param angle
	 * @return
	 */
	public static float checkAdjustY(float speed, float angle) {
		float yDiff = 0;
		
		yDiff = (float)(speed * Math.sin(angle/180.0*Math.PI));
		
		return yDiff;
	}
}
